var otherFiles = [];//存放文件流
var fileNum = 0;

function handleUpload(evn) {
    var name = event.target.files[0].name;//获取上传的文件名

    var file = event.target.files[0];
    if (window.FileReader) {
        var reader = new FileReader();
        reader.readAsDataURL(file);
        //监听文件读取结束后事件
        reader.onloadend = function (e) {
            var id = $(evn).attr('id');
            if (id == 'other') {
                var index = otherFiles.length;
                otherFiles.push($("#other")[0].files[0]);
                fileNum += 1;

                var span = "<div class='col-md-3 otherName_" + index + "'>" +
                                "<div style='height: 90px'><input id='name_" + index + "' type='text' value='" + name + "'/></div>" +
                                "<div class='btn' title='删除' style='margin-left: 20px' onclick='deleteFile(" + index + ")'>" +
                                    "<i class='fa fa-remove fa-lg'></i>" +
                                "</div>" +
                            "</div>";
                $(".other").append(span);
            } else {
                var num = id.substring(5);
                var img = "<img src='" + e.target.result + "' hidden='hidden' id='i_" + num + "' width='180px'" +
                                " height='100px' onclick='imgShow(" + num + ")'/>" +
                            "<a href='#' onclick='imgShow(" + num + ")'>" + name + "</a>";
                $("#" + num).html(img);
                //$("#reUpload").html("重新上传");
            }
        };
    }

    var divObj = $(evn).prev();//获取div的DOM对象
    $(divObj).html("重新上传");
}

function deleteFile(index) {
    layer.confirm('确定删除？', {
        btn: ['确定', '取消']
    }, function () {
        $("#other").val('');
        otherFiles.splice(index, 1);
        $(".otherName_" + index).attr("hidden", "hidden");
        layer.msg('删除成功');
    })
}

function imgShow(num) {
    /*var id = $("#i_" + num);
        if (id.is(":hidden")) {
            id.removeAttr("hidden");
        } else {
            id.attr("hidden", "hidden");
    }*/
}